import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components'

import { AtCurtain } from 'taro-ui'

import XDivider from '../../components/XDivider'

import './index.scss'

export default class extends Component {

  state = {
    isCurtainOpened: false
  }

  handleToPage = url => {
    Taro.navigateTo({
      url
    })
  }

  onCurtainOpen = () => {
    this.setState(state => ({
      ...state,
      isCurtainOpened: true,
    }))
  }

  onCurtainClose = () => {
    this.setState(state => ({
      ...state,
      isCurtainOpened: false,
    }))
  }

  render() {
    return (
      <View className='home-handle'>
      	<View className='btn-group'>
      		<Button onClick={this.handleToPage.bind(this, '/pages/home/lists/index')} size='mini' className='btn'>查看更多</Button>
      	</View>
      	<View className='link-group'>
      		<View onClick={this.handleToPage.bind(this, '/pages/home/apply/index')}>
        		<Text className='text'>我要上首页</Text>
        	</View>
        	<XDivider />
        	<View onClick={this.onCurtainOpen}>
        		<Text className='text'>关联小程序</Text>
        	</View>
      	</View>
        <AtCurtain
          isOpened={this.state.isCurtainOpened}
          onClose={this.onCurtainClose}
        >
          <View style={{textAlign: 'center', color: '#fff'}}>
            <Text>暂时没有关联的小程序</Text>
          </View>
        </AtCurtain> 
      </View>
    )
  }
}